package com.cn.wanxi.control;

import com.cn.wanxi.common.AjaxReturn;
import com.cn.wanxi.entity.DeleteUser;
import com.cn.wanxi.entity.PagingEntity;
import com.cn.wanxi.entity.SelectOptionEntity;
import com.cn.wanxi.entity.UsersEntity;
import com.cn.wanxi.service.UserVerifySerice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description:
 * @author: mayafei
 * @time: 2020/3/11 16:39
 */
@Controller
@RequestMapping("/user")
public class UserVerifyControl {
    @Autowired
    UserVerifySerice userVerifySerice;
    /**
     * 用户登录
     * @param response
     * @param usersEntity
     */
    @PostMapping("/login")
    @ResponseBody
    void userLogin(HttpServletResponse response,HttpServletRequest request,UsersEntity usersEntity){
        response.setCharacterEncoding("utf-8");
//        System.out.println(usersEntity.toString());
        AjaxReturn.informction(userVerifySerice.userLogin(usersEntity,request),response);
    }

    /**
     返回用户名数据
     */
    @PostMapping("/userInfo")
    @ResponseBody
    void userInfo(HttpServletResponse response, HttpServletRequest request){
        response.setCharacterEncoding("utf-8");
        AjaxReturn.informction(userVerifySerice.userInfo(request),response);
    }

    /**
     * 取出方向下拉列表
     * @param response
     * @param selectOptionEntity
     */
    @PostMapping("/option")
    @ResponseBody
    void selectOption(HttpServletResponse response, SelectOptionEntity selectOptionEntity){
        response.setCharacterEncoding("utf-8");
        AjaxReturn.informction(userVerifySerice.selectOption(selectOptionEntity),response);
    }

    /**
     * 取出教师数据
     * @param pagingEntity
     * @param response
     */
    @PostMapping("/dataInfo")
    @ResponseBody
    void dataInfo(PagingEntity pagingEntity,HttpServletResponse response){
        response.setCharacterEncoding("utf-8");
        AjaxReturn.informction(userVerifySerice.dataInfo(pagingEntity),response);
    }

    /**
     * 加载导航数据
     * @param type
     * @param response
     */
    @PostMapping("/navigation")
    @ResponseBody
    void navigationData(String type,HttpServletResponse response){
        response.setCharacterEncoding("utf-8");
        AjaxReturn.informction(userVerifySerice.navigationData(type),response);
    }

    /**
     * 删除单条用户信息
     * @param deleteUser
     * @param response
     */
    @PostMapping("/delete")
    @ResponseBody
    void deleteUser(DeleteUser deleteUser,HttpServletResponse response){
        response.setCharacterEncoding("utf-8");
        AjaxReturn.informction(userVerifySerice.deleteUser(deleteUser),response);
    }

    /**
     * 删除多条信息
     * @param allID
     * @param role
     * @param response
     */
    @PostMapping("/moreDelete")
    @ResponseBody
    void moreDelete(String allID,String role,HttpServletResponse response){
        response.setCharacterEncoding("utf-8");
        AjaxReturn.informction(userVerifySerice.moreDelete(allID,role),response);
    }
}
